var addTwoNumbers = function(l1, l2) {
    const arr = [];

    if(l1.length > l2.length) {
        a1 = l2;a2 = l1
    }else{
        a1 = l1;a2 = l2
    }
    for(let i = 0;i < a1.length;i++) {
        if(arr[i] == null) arr[i]=0;
        arr[i]= Math.floor((a1[i] + a2[i] +arr[i])%10 );
        if(a1[i] + a2[i]>=10){
            arr[i+1]=1
        }
    }
    for(let j = a1.length;j < a2.length;j++) {
        if(arr[j] == null) arr[j]=0;
        if( a2[j]+arr[j] >=10){
            arr[j+1]=1
        }
        arr[j] = Math.floor((a2[j]+arr[j]) %10)    
    }
    console.log(arr)
};

addTwoNumbers([9,9,9],[9,9])